package com.fxsh168.server.base;

import android.app.Activity;

import java.util.Stack;

public class BaseActivityForClose {

    public static Stack<Activity> activityStack=new Stack<>();//把所有的activity放入其中,然后使用这个方法遍历

    /**
     * 根据activity的 名字获得activity的实例
     * */
    public static <T extends Activity> T getActivity(Class<T> cls){
        Activity act = null;
        for (int i = 0, size = activityStack.size(); i < size; i++){
            act =  activityStack.get(i);
            if(act.getClass() == cls){
                return (T)act;
            }
        }
        return null;
    }

    //删除除了特殊的activity
    public static <T> T removeActivity(Class<T> cls1,Class<T> cls2){
        Activity act = null;
        for (int i = 0, size = activityStack.size(); i < size; i++){
            act =  activityStack.get(i);
            if(act.getClass() != cls1||act.getClass()!=cls2){
                act.finish();
                return (T)act;
            }
        }
       return  (T)null;
    }
}
